//
//  LJFCommentsModel.m
//  SevenZhou
//
//  Created by qianfeng on 15/9/22.
//  Copyright (c) 2015年 ljf. All rights reserved.
//

#import "LJFCommentsModel.h"
#import "Helper.h"

@implementation LJFCommentsModel

-(instancetype)initWithDictionary:(NSDictionary *)dict
{
    if (self = [super init])
    {
        _author = dict[@"author"];
        _content = dict[@"content"];
        _create = dict[@"create"];
        _head_pic = dict[@"head_pic"];
        _pic_path = dict[@"pic_path"];
        _rank = dict[@"rank"];
        
        if ([dict[@"re_content"] length] > 0)
        {
            _re_content = [NSString stringWithFormat:@"客服回复:%@",dict[@"re_content"]];
        }else
        {
           _re_content = dict[@"re_content"];
        }
        _heigth_cell = [self getcellHeigthWithcontent:dict[@"content"] andpicArr:dict[@"pic_path"] andRcontent:dict[@"re_content"]];
    }
    
    return self;
}

- (CGFloat)getcellHeigthWithcontent:(NSString *)content andpicArr:(NSArray *)picarr andRcontent:(NSString *)re_content
{
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    
    CGFloat width = (screenWidth - 100 - 15)/4.0;
    
    CGFloat contentW = [Helper heightOfString:content font:[UIFont systemFontOfSize:12] width:screenWidth - 80];
    _contentH = contentW;
    
    CGFloat re_contentW = [Helper heightOfString:re_content font:[UIFont systemFontOfSize:12] width:screenWidth - 80];
    if (re_contentW > 0)
    {
        re_contentW = re_contentW + 5;
    }
    
    CGFloat imgW;
    
    if (picarr.count == 0)
    {
        imgW = 0;
    }
    else
    {
        if (picarr.count >= 5)
        {
            imgW = width*2 + 5  + 5;
        }
        else
        {
            imgW = width + 5 ;
        }
    }
    _imgH = imgW;
    
    CGFloat cellHeigth = 40 + contentW  + imgW  + re_contentW + 5;
    
    return cellHeigth;
}

@end
